########################################
## Water-Energy Analysis Code
########################################

rm(list=ls())
options(scipen=999)

## libraries
pacman::p_load(foreign,plm,lmtest,multiwayvcov,xtable,pastecs,Hmisc,readstata13,plyr,stargazer,ordinal,doBy)

## loading data
setwd("~/Dropbox/Water_MeirVijayJohannes/Data(Final)/Exploration")
water <- read.dta13("~/Dropbox/Water_MeirVijayJohannes/Data(Final)/Final/waterenergy_FINAL.dta")

######################################################
######################################################
## VARIABLES/PREP: Run Before other Tables/Fig Creation
######################################################
######################################################

# social capital index
water$social_capital <- water$b2_1_pol_party + water$b2_2_rel_caste_orgs + water$b2_3a_coops + water$b2_3b_farmers_assoc + water$b2_3c_tradeunions + water$b2_3d_welfare + water$b2_3e_cultural + water$b2_3f_sports + water$b2_3g_panchayat

water$elec_avail <- water$d2_9e_elec_kharif_avail + water$d2_9f_elec_rabi_avail

# changing 6 to NA values
water$b2_4_trust_stategov[water$b2_4_trust_stategov==6] <- NA
water$b2_5_trust_natlgov [water$b2_5_trust_natlgov==6] <- NA

# logarthimized land and expenditure 
water$log_land <- log(water$c1_12_owned_land+1)
water$log_expenditure <- log(water$c2_2_spend)

# fixing a prob w/ these vars' values
water$h4_2_elec_invest_support[water$h4_2_elec_invest_support==6] <- NA
water$h3_2_price_pref[water$h3_2_price_pref==6] <- NA
water$h3_5_meter[water$h3_5_meter==4] <- NA
water$h3_2_price_pref[water$h3_2_price_pref==6] <- NA

## Bihar Tradeoff Inversion

water$h4_4_subsidy_tradeoff1 <- -1*water$h4_4_subsidy_tradeoff1
water$h4_4_subsidy_tradeoff1 <- water$h4_4_subsidy_tradeoff1+6

water$h4_5_subsidy_tradeoff2 <- -1*water$h4_5_subsidy_tradeoff2
water$h4_5_subsidy_tradeoff2 <- water$h4_5_subsidy_tradeoff2+6

## Raj Guj Policy Inversions

# inverting for consistency
water$r_pref[water$a3_1_state!="Bihar"] <- 1
water$r_pref[water$h3_1_pol_pref==2] <- 3
water$r_pref[water$h3_1_pol_pref==3] <- 2
water$r_pref[water$h3_1_pol_pref==4] <- NA

# inverting so that higher numbers mean more support for a price ceiling
water$h3_7_price_ceiling <- -1*water$h3_7_price_ceiling
water$h3_7_price_ceiling <- water$h3_7_price_ceiling+5
water$h3_7_price_ceiling[water$h3_7_price_ceiling==0] <- NA

# Recoding so that high values mean more support for diesel
water$h3_6_subsidy <- -1*water$h3_6_subsidy
water$h3_6_subsidy <- water$h3_6_subsidy+5
water$h3_6_subsidy[water$h3_6_subsidy==0] <- NA

#############
### media exposure vars - cleaning and index creation ##
#############

# changing 8 to NA values
water$b2_6_state_news[water$b2_6_state_news==8] <- NA
water$b2_7_natl_news [water$b2_7_natl_news==8] <- NA

# inverting so that a higher value indicates more frequent media exposure  
water$b2_6_state_news <- -1*water$b2_6_state_news
water$b2_6_state_news <- water$b2_6_state_news+8

water$b2_7_natl_news <- -1*water$b2_7_natl_news
water$b2_7_natl_news <- water$b2_7_natl_news+8

media <- c("b2_6_state_news","b2_7_natl_news")
x <- water[media]          
cor(x, use="pairwise.complete.obs")
## corr is almost 1

# creating an index

water$media <- .5*water$b2_6_state_news + .5*water$b2_7_natl_news
summary(water$media)

##########
# creating categorical vars for state trust l,m,h,
#########
water$sta.cat <- NA
water$sta.cat[water$b2_4_trust_stategov==1|water$b2_4_trust_stategov==2] <- 1
water$sta.cat[water$b2_4_trust_stategov==3] <- 2
water$sta.cat[water$b2_4_trust_stategov==4|water$b2_4_trust_stategov==5] <- 3

#################
####### Subsetting - MUST DO THIS LAST AFTER ALL VAR TRANSFORMATION ABOVE IS COMPLETE ##
##################

## Gujarat and Raj Subset
rajguj <- water[water$a3_1_st_code!=10, ]

## STATE ID Dummies For State Tables

water$bihar <- 0
water$bihar[water$a3_1_state=="Bihar"] <- 1
water$guj <- 0
water$guj[water$a3_1_state=="Gujraat"] <- 1
water$raj <- 0
water$raj[water$a3_1_state=="Rajasthan"] <- 1

# then subset out each state
bihar <- subset(water,water$a3_1_st_code==10)
guj <- subset(water,water$a3_1_st_code==24)
raj <- subset(water,water$a3_1_st_code==8)

### subset by level of state trust (l, m, h)
l <- water[which(water$sta.cat==1),]
m <- water[which(water$sta.cat==2),]
h <- water[which(water$sta.cat==3),]

### subsets bt state
b.l <- bihar[which(bihar$sta.cat==1),]
b.m <- bihar[which(bihar$sta.cat==2),]
b.h <- bihar[which(bihar$sta.cat==3),]

g.l <- guj[which(guj$sta.cat==1),]
g.m <- guj[which(guj$sta.cat==2),]
g.h <- guj[which(guj$sta.cat==3),]

r.l <- raj[which(raj$sta.cat==1),]
r.m <- raj[which(raj$sta.cat==2),]
r.h <- raj[which(raj$sta.cat==3),]

summary(m$b2_5_trust_natlgov)

# subset by level of state trust (1,2,3,4,5)
t1 <- water[which(water$b2_4_trust_stategov==1),]
t2 <- water[which(water$b2_4_trust_stategov==2),]
t3 <- water[which(water$b2_4_trust_stategov==3),]
t4 <- water[which(water$b2_4_trust_stategov==4),]
t5 <- water[which(water$b2_4_trust_stategov==5),]

################################################################
### END VAR CREATION / SUBSETTING PREP
################################################################

### Table of Associations and Social Capital 

Association <- c("Political Party ", "Religous or Caste Org.","Cooperatives","Farmer's Associations","Trade Unions","Welfare Organizations","Cultural Organizations","Sports Organizations","Panchayat Member")
Counts <- c(sum(na.omit(water$b2_1_pol_party)), sum(na.omit(water$b2_2_rel_caste_orgs)), sum(na.omit(water$b2_3a_coops)), sum(na.omit(water$b2_3b_farmers_assoc)), sum(na.omit(water$b2_3c_tradeunions)), sum(na.omit(water$b2_3d_welfare)), sum(na.omit(water$b2_3e_cultural)), sum(na.omit(water$b2_3f_sports)), sum(na.omit(water$b2_3g_panchayat)))

assocs <- cbind(Association,Counts)

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/soccap_assocs.tex")
print(xtable(assocs),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

#############################
#############################
### REGRESSION TABLES
#############################
#############################

# elec in last election
model1a <- lm(h1_1_elec_policy_impt1 ~  b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov1a <-cluster.vcov(model1a, as.factor(water$a3_4_1_vill_code)) 
coef1a <- coeftest(model1a, m.vcov1a)

model1b <- lm(h1_1_elec_policy_impt1 ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov1b <-cluster.vcov(model1b, as.factor(water$a3_4_1_vill_code)) 
coef1b <- coeftest(model1b, m.vcov1b)

model1c <- lm(h1_1_elec_policy_impt1 ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov1c <-cluster.vcov(model1c, as.factor(water$a3_4_1_vill_code)) 
coef1c <- coeftest(model1c, m.vcov1c)

# elec in previous election
model2a <- lm(h1_2_elec_policy_impt2 ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov2a <-cluster.vcov(model2a, as.factor(water$a3_4_1_vill_code)) 
coef2a <- coeftest(model2a, m.vcov2a)

model2b <- lm(h1_2_elec_policy_impt2 ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov2b <-cluster.vcov(model2b, as.factor(water$a3_4_1_vill_code)) 
coef2b <- coeftest(model2b, m.vcov2b)

model2c <- lm(h1_2_elec_policy_impt2 ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov2c <-cluster.vcov(model2c, as.factor(water$a3_4_1_vill_code)) 
coef2c <- coeftest(model2c, m.vcov2c)

# table 1
fit.list1 <- list(model1a, model1b,model1c, model2a, model2b, model2c)
se1 <- list(coef1a[,2],coef1b[,2],coef1c[,2],coef2a[,2],coef2b[,2],coef2c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/reg_table1.tex")
stargazer(title = "Electric Policy Importance in Two Most Recent Elections",
          se = se1,
          header = F,
          fit.list1,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

### REGRESSIONS ON DIESEL -- TABLE 2

#dv 3
model3a <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov3a <-cluster.vcov(model3a, as.factor(water$a3_4_1_vill_code)) 
coef3a <- coeftest(model3a, m.vcov3a)

model3b <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov3b <-cluster.vcov(model3b, as.factor(water$a3_4_1_vill_code)) 
coef3b <- coeftest(model3b, m.vcov3b)

model3c <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
              as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov3c <-cluster.vcov(model3c, as.factor(water$a3_4_1_vill_code)) 
coef3c <- coeftest(model3c, m.vcov3c)

#dv 4
model4a <- lm(h1_4_dsl_polcy_impt2 ~b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov4a <-cluster.vcov(model4a, as.factor(water$a3_4_1_vill_code)) 
coef4a <- coeftest(model4a, m.vcov4a)

model4b <- lm(h1_4_dsl_polcy_impt2 ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov4b <-cluster.vcov(model4b, as.factor(water$a3_4_1_vill_code)) 
coef4b <- coeftest(model4b, m.vcov4b)

model4c <- lm(h1_4_dsl_polcy_impt2 ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
              as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov4c <-cluster.vcov(model4c, as.factor(water$a3_4_1_vill_code)) 
coef4c <- coeftest(model4c, m.vcov4c)

# table 2
fit.list2 <- list(model3a, model3b,model3c, model4a, model4b, model4c)
se2 <- list(coef3a[,2],coef3b[,2],coef3c[,2],coef4a[,2],coef4b[,2],coef4c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump","Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/reg_table2.tex")
stargazer(title = "Diesel Policy Importance in Two Most Recent Elections",
          se = se2,
          header = F,
          fit.list2,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

#dv 4 tradeoff 1
model5a <- lm(h4_4_subsidy_tradeoff1 ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov5a <-cluster.vcov(model5a, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef5a <- coeftest(model5a, m.vcov5a)

model5b <- lm(h4_4_subsidy_tradeoff1 ~b2_4_trust_stategov + b2_5_trust_natlgov  + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov5b <-cluster.vcov(model5b, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef5b <- coeftest(model5b, m.vcov5b)

model5c <- lm(h4_4_subsidy_tradeoff1 ~b2_4_trust_stategov + b2_5_trust_natlgov + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov5c <-cluster.vcov(model5c, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef5c <- coeftest(model5c, m.vcov5c)

#dv 5 tradeoff 2
model6a <- lm(h4_5_subsidy_tradeoff2 ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=water)
m.vcov6a <-cluster.vcov(model6a, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef6a <- coeftest(model6a, m.vcov6a)

model6b <- lm(h4_5_subsidy_tradeoff2 ~ b2_4_trust_stategov + b2_5_trust_natlgov + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
m.vcov6b <-cluster.vcov(model6b, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef6b <- coeftest(model6b, m.vcov6b)

model6c <- lm(h4_5_subsidy_tradeoff2 ~ b2_4_trust_stategov + b2_5_trust_natlgov + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)
m.vcov6c <-cluster.vcov(model6c, as.factor(water$a3_4_1_vill_code[water$a3_1_state=="Bihar"])) 
coef6c <- coeftest(model6c, m.vcov6c)

# table 3 - bihar only
fit.list3 <- list(model5a, model5b,model5c, model6a, model6b, model6c)
se3 <- list(coef5a[,2],coef5b[,2],coef5c[,2],coef6a[,2],coef6b[,2],coef6c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/reg_table3.tex")
stargazer(title = "Electric vs. Diesel Subsidy Tradeoffs (Bihar only)",
          se = se3,
          header = F,
          fit.list3,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Tradeoff 1","Tradeoff 2"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

####
# O-Logit Replications of Three Main models 
# Note need to use Blocks FE, not Villages - using village FEs =problems w/ convergence
####

### O-LOGITS ON ELEC -- TABLE 

# elec in last election
model7a <- clm(as.factor(h1_1_elec_policy_impt1) ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=water)

model7b <- clm(as.factor(h1_1_elec_policy_impt1) ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code),data=water)

model7c <- clm(as.factor(h1_1_elec_policy_impt1) ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)

# elec in previous election
model8a <- clm(as.factor(h1_2_elec_policy_impt2) ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=water)

model8b <- clm(as.factor(h1_2_elec_policy_impt2) ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl +  social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code),data=water)

model8c <- clm(as.factor(h1_2_elec_policy_impt2) ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)

# o-logit table 1 
fit.list4 <- list(model7a, model7b,model7c, model8a, model8b, model8c)
olog.omit.list <-c("a3_3_1_block_code", "e1_1_source", "b1_6a_govt_caste")
olog.omit.labs <- c("Block FE", "Source FE", "Govt caste FE")
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/o-log1.tex")
stargazer(title = "Electric Policy Importance in Two Most Recent Elections [Estimated w/ Ordinal Logits]",
          header = F,
          fit.list4,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = olog.omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("B FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","Yes","No","Yes")))
sink()

### REGRESSIONS ON DIESEL -- TABLE 2

#dv diesel in last elec 
model9a <- clm(as.factor(h1_3_dsl_policy_impt1) ~ b2_4_trust_stategov + b2_5_trust_natlgov +  as.factor(a3_3_1_block_code),data=water)

model9b <- clm(as.factor(h1_3_dsl_policy_impt1) ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +as.factor(a3_3_1_block_code),data=water)

model9c <- clm(as.factor(h1_3_dsl_policy_impt1) ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)

#diesel in prev election
model10a <- clm(as.factor(h1_4_dsl_polcy_impt2) ~  b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=water)

model10b <- clm(as.factor(h1_4_dsl_polcy_impt2) ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code),data=water)

model10c <- clm(as.factor(h1_4_dsl_polcy_impt2) ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) +
                  as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=water)

# o-logtable 2
fit.list5 <- list(model9a, model9b,model9c,model10a, model10b,model10c)
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/o-log2.tex")
stargazer(title = "Diesel Policy Importance in Two Most Recent Elections [Estimated w/ Ordinal Logits]",
          header = F,
          fit.list5,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = olog.omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","Yes","No","Yes")))
sink()

## O-logit for bihar subsdidy tradeoff DVs

bihar <- water[water$a3_1_st_code==10, ]
nrow(bihar)

#dv 4 tradeoff 1
model11a <- clm(as.factor(h4_4_subsidy_tradeoff1) ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=bihar)

model11c <- clm(as.factor(h4_4_subsidy_tradeoff1) ~  b2_4_trust_stategov + b2_5_trust_natlgov + social_capital +media+  as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=bihar)

#dv 5 tradeoff 2
model12a <- clm(as.factor(h4_5_subsidy_tradeoff2) ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=bihar)

model12c <- clm(as.factor(h4_5_subsidy_tradeoff2) ~  b2_4_trust_stategov + b2_5_trust_natlgov + social_capital +media + as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=bihar)

# table 3 - bihar only
fit.list6 <- list(model11a,model11c,model12a,model12c)
cov.labs <- c( "Trust in State Govt.", "Trust in National Govt.", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/o-log3.tex")
stargazer(title = "Electric vs. Diesel Subsidy Tradeoffs (Bihar only)",
          header = F,
          fit.list6,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = olog.omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Tradeoff 1","Tradeoff 2"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes","Yes"),
                           c("Government Caste FE?","No","Yes","No","Yes")))
sink()

### DESCRIPTIVE FIGURES ###

setwd("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Figures")

pdf(file = "bar1.pdf", height = 5, width = 5)
barplot(prop.table(table(factor(water$h1_1_elec_policy_impt1,levels=1:4))), xlab="Importance",ylab="Proportion",main="Elec Subsidy: Last Election")
dev.off()

pdf(file = "bar2.pdf", height = 5, width = 5)
barplot(prop.table(table(factor(water$h1_2_elec_policy_impt2,levels=1:4))), xlab="Importance",ylab="Proportion",main="Elec Subsidy: Previous Election")
dev.off()

pdf(file = "bar3.pdf", height = 5, width = 5)
barplot(prop.table(table(factor(water$h1_3_dsl_policy_impt1,levels=1:4))), xlab="Importance",ylab="Proportion",main="Diesel Subsidy: Last Election")
dev.off()

pdf(file = "bar4.pdf", height = 5, width = 5)
barplot(prop.table(table(factor(water$h1_4_dsl_polcy_impt2,levels=1:4))), xlab="Importance",ylab="Proportion",main="Diesel Subsidy: Previous Election")
dev.off()

########
### Trust and Social Capital Ouputs ### 
########

table1 <- table(water$b2_4_trust_stategov, water$b2_5_trust_natlgov)
pdf(file = "trust.pdf", height = 5, width = 5)
plot((table1), ylab= "State Govt", xlab= "Natl Govt",main="Trust")
dev.off()

table2 <- table(water$social_capital, water$b2_5_trust_natlgov)
pdf(file = "soc_natl.pdf", height = 5, width = 5)
plot((table2), ylab= "Natl Govt Trust", xlab= "Social Capital",main="")
dev.off()

table3 <- table(water$social_capital, water$b2_4_trust_stategov)
pdf(file = "soc_state.pdf", height = 5, width = 5)
plot((table3), ylab= "State Govt Trust", xlab= "Social Capital",main="")
dev.off()

#######################################
#######################################
# SUMMARY TABLES
#######################################
#######################################

## 

## creating separate variables for categorical vars
# govt caste
attach(water)
water$sc <- 0
water$sc[water$b1_6a_govt_caste==1] <- 1
water$st <- 0
water$st[water$b1_6a_govt_caste==2] <- 1
water$obc <- 0
water$obc[water$b1_6a_govt_caste==3] <- 1
water$gen <- 0
water$gen[water$b1_6a_govt_caste==4] <- 1
water$other <- 0
water$other[water$b1_6a_govt_caste==5] <- 1

# source  # note there are no no irrig. farmers
water$surf.only <- 0
water$surf.only[water$e1_1_source==2] <- 1
water$bore.only <- 0
water$bore.only[water$e1_1_source==3] <- 1
water$both <- 0
water$both[water$e1_1_source==4] <- 1
detach(water)

colnames(water)
vars.water <- c( "h1_1_elec_policy_impt1", "h1_2_elec_policy_impt2", "h1_3_dsl_policy_impt1", "h1_4_dsl_polcy_impt2",
                 "h4_1_dsl_sub_support","h4_2_elec_invest_support","h4_3_elec_vs_dsl","h4_4_subsidy_tradeoff1",         
                 "h4_5_subsidy_tradeoff2","h3_1_pol_pref","h3_2_price_pref","h3_3_water_limit",               
                 "h3_4_elec_limit","h3_5_meter","h3_6_subsidy","h3_7_price_ceiling","social_capital", "media","b2_4_trust_stategov","b2_5_trust_natlgov","d2_8_elec","d2_10_dsl","c1_12_owned_land","c2_2_spend","b1_4_school","sc","st","obc",
                 "gen","other","surf.only","bore.only","both")

vars.bihar <- c( "h1_1_elec_policy_impt1", "h1_2_elec_policy_impt2", "h1_3_dsl_policy_impt1", "h1_4_dsl_polcy_impt2",
                 "h4_1_dsl_sub_support","h4_2_elec_invest_support","h4_3_elec_vs_dsl","h4_4_subsidy_tradeoff1",         
                 "h4_5_subsidy_tradeoff2","social_capital","media","b2_4_trust_stategov",
                 "b2_5_trust_natlgov","d2_8_elec","d2_10_dsl","c1_12_owned_land","log_expenditure","b1_4_school","sc","st","obc",
                 "gen","other","surf.only","bore.only","both")

vars.guj_raj <- c( "h1_1_elec_policy_impt1", "h1_2_elec_policy_impt2", "h1_3_dsl_policy_impt1", "h1_4_dsl_polcy_impt2",
                   "h3_1_pol_pref","h3_2_price_pref","h3_3_water_limit",
                   "h3_4_elec_limit","h3_5_meter","h3_6_subsidy","h3_7_price_ceiling","social_capital","media","b2_4_trust_stategov",
                   "b2_5_trust_natlgov","d2_8_elec","d2_10_dsl","c1_12_owned_land","log_expenditure","b1_4_school","sc","st","obc",
                   "gen","other","surf.only","bore.only","both")

# then subset out each state
bihar <- subset(water,water$a3_1_st_code==10)
guj <- subset(water,water$a3_1_st_code==24)
raj <- subset(water,water$a3_1_st_code==8)

# then create dfs that are the vars for each state
w.stats <- water[vars.water]
b.stats <- bihar[vars.bihar]
g.stats <- guj[vars.guj_raj]
r.stats <- raj[vars.guj_raj]

colnames(w.stats) <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Diesel subsidy support","Electric investment support","Electricity vs. diesel","Subsidy tradeoff 1","Subsidy tradeoff 2","Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

colnames(b.stats) <-   c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Diesel subsidy support","Electric investment support","Electricity vs. diesel","Subsidy tradeoff 1","Subsidy tradeoff 2","Social Capital Index","News Exposure", "State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

colnames(g.stats) <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

colnames(r.stats) <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

## 1st table (all water)

# colnames for all water table
Num.Obs. <- apply(w.stats, 2, function(x){sum(!is.na(x))})
Means <- sapply(w.stats, mean, na.rm=TRUE)
SD <- sapply(w.stats, sd, na.rm=TRUE)
Min <- sapply(w.stats, min, na.rm=TRUE)
Max <- sapply(w.stats, max, na.rm=TRUE)

# binding these columns

w.summ <- round(cbind(Num.Obs.,Means,SD, Min, Max),digits=2)

# xtable out all water
rws <- seq(1, (nrow(w.summ)-1), by = 2)
col <- rep("\\rowcolor[gray]{0.95}", length(w.summ))
print(xtable(w.summ), booktabs = TRUE,add.to.row = list(pos = as.list(rws), command = col))



sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/water_summ.tex")
print(xtable(w.summ,digits=c(0,0,2,2,0,0)),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### 2nd table (bihar)

# colnames for bihar table
Num.Obs. <- apply(b.stats, 2, function(x){sum(!is.na(x))})
Means <- sapply(b.stats, mean, na.rm=TRUE)
SD <- sapply(b.stats, sd, na.rm=TRUE)
Min <- sapply(b.stats, min, na.rm=TRUE)
Max <- sapply(b.stats, max, na.rm=TRUE)

# binding these columns
b.summ <- round(cbind(Num.Obs.,Means,SD, Min, Max),digits = 2)

# xtable out bihar
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/bihar_summ.tex")
print(xtable(b.summ,digits=c(0,0,2,2,0,0)),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### 3rd table (Guj)

# colnames for guj table
Num.Obs. <- apply(g.stats, 2, function(x){sum(!is.na(x))})
Means <- sapply(g.stats, mean, na.rm=TRUE)
SD <- sapply(g.stats, sd, na.rm=TRUE)
Min <- sapply(g.stats, min, na.rm=TRUE)
Max <- sapply(g.stats, max, na.rm=TRUE)

# binding these columns
g.summ <- round(cbind(Num.Obs.,Means,SD, Min, Max),digits=2)

# xtable out Gujarat
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/guj_summ.tex")
print(xtable(g.summ,digits=c(0,0,2,2,0,0)),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### 4th table (Raj)

# colnames for raj table
Num.Obs. <- apply(r.stats, 2, function(x){sum(!is.na(x))})
Means <- sapply(r.stats, mean, na.rm=TRUE)
SD <- sapply(r.stats, sd, na.rm=TRUE)
Min <- sapply(r.stats, min, na.rm=TRUE)
Max <- sapply(r.stats, max, na.rm=TRUE)

# binding these columns
r.summ <- round(cbind(Num.Obs.,Means,SD, Min, Max),digits = 2)

# xtable out raj
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/raj_summ.tex")
print(xtable(r.summ,digits=c(0,0,2,2,0,0)),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

#################
#################
## correlation matrices ##
#################
#################

# note now changing colnames for correlation matrices
colnames(w.stats) <- c("1","2","3","4","5","6","7","8","9","10","11","12",
                       "13","14","15","16","17","18","19","20","21","22","23",
                       "24","25","26","27","28","29","30","31","32","33")
colnames(b.stats) <- c("1","2","3","4","5","6","7","8","9","10","11","12",
"13","14","15","16","17","18","19","20","21","22","23","24","25","26")
colnames(g.stats) <- c("1","2","3","4","5","6","7","8","9","10","11","12",
                       "13","14","15","16","17","18","19","20","21",
                       "22","23","24","25","26","27","28")
colnames(r.stats) <-  c("1","2","3","4","5","6","7","8","9","10","11","12",
                          "13","14","15","16","17","18","19","20","21",
                          "22","23","24","25","26","27","28")

w.statsM <- as.matrix(w.stats)
water_corr <- cor(w.statsM, use="pairwise.complete.obs") 
water_corr2 <- round(water_corr, digits =2)

b.statsM <- as.matrix(b.stats)
bihar_corr <- cor(b.statsM, use="pairwise.complete.obs") 
bihar_corr2 <- round(bihar_corr, digits =2)

g.statsM <- as.matrix(g.stats)
guj_corr <- cor(g.statsM, use="pairwise.complete.obs") 
guj_corr2 <- round(guj_corr, digits =2)

r.statsM <- as.matrix(r.stats)
raj_corr <- cor(r.statsM, use="pairwise.complete.obs") 
raj_corr2 <- round(raj_corr, digits =2)

# now creating a vector of x-axis labels to cbind to the matrix - needs to be done AFTER the correlation matrix is calucalted and then cbinded to matrix, xtabling out

# full sample
Variables <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Diesel subsidy support","Electric investment support","Electricity vs. diesel","Subsidy tradeoff 1","Subsidy tradeoff 2","Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

water_corr3 <- cbind(Variables,water_corr2)
View(water_corr3)
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/water_corr.tex")
print(xtable(water_corr3),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### Bihar only
Variables <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Diesel subsidy support","Electric investment support","Electricity vs. diesel","Subsidy tradeoff 1","Subsidy tradeoff 2","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")    

bihar_corr3 <- cbind(Variables,bihar_corr2)
View(bihar_corr3)
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/bihar_corr.tex")
print(xtable(bihar_corr3),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### Gujarat only
Variables <-  c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   

guj_corr3 <- cbind(Variables,guj_corr2)

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/guj_corr.tex")
print(xtable(guj_corr3),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

### Rajasthan only
Variables <- c("Electricity policy impt (1)", "Elec policy impt (2)", "Diesel policy impt (1)", "Diesel policy impt (2)", "Politician preference","Price preference","Water limit?","Electricity limit?","Electricity meter","Diesel subsidy","Diesel price ceiling","Social Capital Index","News Exposure","State govt. trust", "National govt. trust","Electric Pump User","Diesel Pump Owner","Land owned (bighas)","Monthly expenditure (INR)","Years of schooling","Scheduled caste","Scheduled tribe", "Other Backward Caste", "General caste", "Other caste","Surface irrig. only","Bore irrig. only","Both surface and bore")   
raj_corr3 <- cbind(Variables,raj_corr2)

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/raj_corr.tex")
print(xtable(raj_corr3),floating=FALSE,font.size="tiny",latex.environments="center")
sink()

###############################################
###############################################
### STATE TABLES ##
###############################################
###############################################

### REGRESSIONS ON ELEC -- STATE TABLE 1 

# dv 1
stat1a <- lm(h1_1_elec_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + as.factor(a3_4_village),data=water)
s.vcov1a <-cluster.vcov(stat1a, as.factor(water$a3_4_1_vill_code)) 
coef1a <- coeftest(stat1a, s.vcov1a)

stat1b <- lm(h1_1_elec_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov1b <-cluster.vcov(stat1b, as.factor(water$a3_4_1_vill_code)) 
coef1b <- coeftest(stat1b, s.vcov1b)

stat1c <- lm(h1_1_elec_policy_impt1 ~  b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov1c <-cluster.vcov(stat1c, as.factor(water$a3_4_1_vill_code)) 
coef1c <- coeftest(stat1c, s.vcov1c)

## dv 2
stat2a <- lm(h1_2_elec_policy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + as.factor(a3_4_village),data=water)
s.vcov2a <-cluster.vcov(stat2a, as.factor(water$a3_4_1_vill_code)) 
coef2a <- coeftest(stat2a, s.vcov2a)

stat2b <- lm(h1_2_elec_policy_impt2 ~  b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov2b <-cluster.vcov(stat2b, as.factor(water$a3_4_1_vill_code)) 
coef2b <- coeftest(stat2b, s.vcov2b)

stat2c <- lm(h1_2_elec_policy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov2c <-cluster.vcov(stat2c, as.factor(water$a3_4_1_vill_code)) 
coef2c <- coeftest(stat2c, s.vcov2c)

# state table 1
fit.list1 <- list(stat1a,stat1b,stat1c,stat2a,stat2b,stat2c)
se1 <- list(coef1a[,2],coef1b[,2],coef1c[,2],coef2a[,2],coef2b[,2],coef2c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling","Trust in State Govt. X Gujarat","Trust in State Govt. X Rajasthan","Trust in National Govt. X Gujarat","Trust in National Govt. X Rajasthan")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/state_table1.tex")
stargazer(title = "Electric Policy Importance in Two Most Recent Elections",
          se = se1,
          header = F,
          fit.list1,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

### REGRESSIONS ON DIESEL -- STATE TABLE 2

#dv 3
stat3a <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + as.factor(a3_4_village),data=water)
s.vcov3a <-cluster.vcov(stat3a, as.factor(water$a3_4_1_vill_code)) 
coef3a <- coeftest(stat3a, s.vcov3a)

stat3b <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl  +social_capital+media+  as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov3b <-cluster.vcov(stat3b, as.factor(water$a3_4_1_vill_code)) 
coef3b <- coeftest(stat3b, s.vcov3b)

stat3c <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital+media+ as.factor(e1_1_source) +
              as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov3c <-cluster.vcov(stat3c, as.factor(water$a3_4_1_vill_code)) 
coef3c <- coeftest(stat3c, s.vcov3c)

#dv 4
stat4a <- lm(h1_4_dsl_polcy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + as.factor(a3_4_village),data=water)
s.vcov4a <-cluster.vcov(stat4a, as.factor(water$a3_4_1_vill_code)) 
coef4a <- coeftest(stat4a, s.vcov4a)

stat4b <- lm(h1_4_dsl_polcy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl + social_capital+ media+ as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov4b <-cluster.vcov(stat4b, as.factor(water$a3_4_1_vill_code)) 
coef4b <- coeftest(stat4b, s.vcov4b)

stat4c <- lm(h1_4_dsl_polcy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:guj + b2_4_trust_stategov:raj + b2_5_trust_natlgov + b2_5_trust_natlgov:guj + b2_5_trust_natlgov:raj + d2_8_elec + d2_10_dsl +social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov4c <-cluster.vcov(stat4c, as.factor(water$a3_4_1_vill_code)) 
coef4c <- coeftest(stat4c, s.vcov4c)

# state table 2
fit.list2 <- list(stat3a,stat3b,stat3c,stat4a,stat4b,stat4c)
se2 <- list(coef3a[,2],coef3b[,2],coef3c[,2],coef4a[,2],coef4b[,2],coef4c[,2])
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/state_table2.tex")
stargazer(title = "Diesel Policy Importance in Two Most Recent Elections",
          se = se1,
          header = F,
          fit.list2,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

######################################################
######################################################
### POLICY INTERACTED WITH PUMP 
######################################################
######################################################

### REGRESSIONS ON ELEC POLICY

### elec policy by pump in last election
pump1a <- lm(h1_1_elec_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + as.factor(a3_4_village),data=water)
s.vcov1a <-cluster.vcov(pump1a, as.factor(water$a3_4_1_vill_code)) 
coef1a <- coeftest(pump1a, s.vcov1a)

pump1b <- lm(h1_1_elec_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov1b <-cluster.vcov(pump1b, as.factor(water$a3_4_1_vill_code)) 
coef1b <- coeftest(pump1b, s.vcov1b)

pump1c <- lm(h1_1_elec_policy_impt1 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov1c <-cluster.vcov(pump1c, as.factor(water$a3_4_1_vill_code)) 
coef1c <- coeftest(pump1c, s.vcov1c)

### elec policy by pump in previous election
pump2a <- lm(h1_2_elec_policy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + as.factor(a3_4_village),data=water)
s.vcov2a <-cluster.vcov(pump2a, as.factor(water$a3_4_1_vill_code)) 
coef2a <- coeftest(pump2a, s.vcov2a)

pump2b <- lm(h1_2_elec_policy_impt2 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov2b <-cluster.vcov(pump2b, as.factor(water$a3_4_1_vill_code)) 
coef2b <- coeftest(pump2b, s.vcov2b)

pump2c <- lm(h1_2_elec_policy_impt2 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) +
as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov2c <-cluster.vcov(pump2c, as.factor(water$a3_4_1_vill_code)) 
coef2c <- coeftest(pump2c, s.vcov2c)

### Pump Table 1 - elec policy 
# table 1
fit.list.pump.1 <- list(pump1a,pump1b,pump1c,pump2a,pump2b,pump2c)
se.pump.1 <- list(coef1a[,2],coef1b[,2],coef1c[,2],coef2a[,2],coef2b[,2],coef2c[,2])
cov.labs <- c("Trust in State Govt.","Trust in National Govt.","Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling","Trust in State Govt. X Elec Pump", "Trust in State Govt. X Diesel Pump", "Trust in Natl. Govt. X Elec Pump","Trust in Natl. Govt. X Diesel Pump")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/pump_reg_table1.tex")
stargazer(title = "Electric Policy Importance and Pump Type, in Two Most Recent Elections",
          se = se.pump.1,
          header = F,
          fit.list.pump.1,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
sink()

### REGRESSIONS ON DIESEL POLICY

### diesel policy by pump in last election
pump3a <- lm(h1_3_dsl_policy_impt1 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + as.factor(a3_4_village),data=water)
s.vcov3a <-cluster.vcov(pump3a, as.factor(water$a3_4_1_vill_code)) 
coef3a <- coeftest(pump3a, s.vcov3a)

pump3b <- lm(h1_3_dsl_policy_impt1 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov3b <-cluster.vcov(pump3b, as.factor(water$a3_4_1_vill_code)) 
coef3b <- coeftest(pump3b, s.vcov3b)

pump3c <- lm(h1_3_dsl_policy_impt1 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital+media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov3c <-cluster.vcov(pump3c, as.factor(water$a3_4_1_vill_code)) 
coef3c <- coeftest(pump3c, s.vcov3c)

### diesel policy by pump in previous election
pump4a <- lm(h1_4_dsl_polcy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + as.factor(a3_4_village),data=water)
s.vcov4a <-cluster.vcov(pump4a, as.factor(water$a3_4_1_vill_code)) 
coef4a <- coeftest(pump4a, s.vcov4a)

pump4b <- lm(h1_4_dsl_polcy_impt2 ~  b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village),data=water)
s.vcov4b <-cluster.vcov(pump4b, as.factor(water$a3_4_1_vill_code)) 
coef4b <- coeftest(pump4b, s.vcov4b)

pump4c <- lm(h1_4_dsl_polcy_impt2 ~ b2_4_trust_stategov + b2_4_trust_stategov:d2_8_elec + b2_4_trust_stategov:d2_10_dsl + b2_5_trust_natlgov + b2_5_trust_natlgov:d2_8_elec + b2_5_trust_natlgov:d2_10_dsl + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(water$b1_6a_govt_caste), data=water)
s.vcov4c <-cluster.vcov(pump4c, as.factor(water$a3_4_1_vill_code)) 
coef4c <- coeftest(pump4c, s.vcov4c)

### Pump Table 2 - diesel policy 

# table 2
fit.list.pump.2 <- list(pump3a,pump3b,pump3c,pump4a,pump4b,pump4c)
se.pump.2 <- list(coef3a[,2],coef3b[,2],coef3c[,2],coef4a[,2],coef4b[,2],coef4c[,2])
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/pump_reg_table2.tex")
stargazer(title = "Diesel Policy Importance and Pump Type, in Two Most Recent Elections",
          se = se.pump.2,
          header = F,
          fit.list.pump.2,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Last Election","Previous Election"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes")))
          sink()
          
          
### RAJASTHAN, GUJARAT ANALYSIS 

r1a <- lm(r_pref ~  b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
r.vcov1a <-cluster.vcov(r1a, as.factor(rajguj$a3_4_1_vill_code))
coefr1a <- coeftest(r1a, r.vcov1a)

r1b <- lm(r_pref ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
r.vcov1b <-cluster.vcov(r1b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr1b <- coeftest(r1b, r.vcov1b)

r1c <- lm(r_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
r.vcov1c <-cluster.vcov(r1c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr1c <- coeftest(r1c, r.vcov1c)

fit.list.r1 <- list(r1a,r1b,r1c)
ser1 <- list(coefr1a[,2],coefr1b[,2],coefr1c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes1.tex")
stargazer(title = "Predictors of Political Preferences for Electric Reliability vs. Pricing",
          se = ser1,
          header = F,
          fit.list.r1,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Preference for Electric Reliability vs. Pricing"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes")))
sink()

########
### Willingness to Pay for Reliable Electricity ##
#######

r2a <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
r.vcov2a <-cluster.vcov(r2a, as.factor(rajguj$a3_4_1_vill_code))
coefr2a <- coeftest(r2a, r.vcov2a)

r2b <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
r.vcov2b <-cluster.vcov(r2b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr2b <- coeftest(r2b, r.vcov2b)

r2c <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
r.vcov2c <-cluster.vcov(r2c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr2c <- coeftest(r2c, r.vcov2c)

fit.list.r2 <- list(r2a,r2b,r2c)
ser2 <- list(coefr2a[,2],coefr2b[,2],coefr2c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes2.tex")
stargazer(title = "Predictors of Willingness to Pay for Reliable Electricity",
          se = ser2,
          header = F,
          fit.list.r2,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Willingness to Pay for Reliable Electricity"),
          add.lines = list(c("Village FE?","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes")))
sink()

########
### O-Logit Replications of Willingness to Pay for Reliable Electricity
#######

r2a <- clm(as.factor(h3_2_price_pref) ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_3_1_block_code),data=rajguj)

r2b <- clm(as.factor(h3_2_price_pref) ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code),data=rajguj)

r2c <- clm(as.factor(h3_2_price_pref) ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_3_1_block_code) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)

fit.list.r2 <- list(r2a,r2b,r2c)
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump","Social Capital (index)","News Exposure" "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_3_1_block_code", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Block FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes2.o-log.tex")
stargazer(title = "O-Logit Estimates, Predictors of Willingness to Pay for Reliable Electricity",
          header = F,
          fit.list.r2,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Willingness to Pay for Reliable Electricity"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes")))
sink()

#########
###Government Limits
########

### limits on groundwater pumping
r3a <- lm(h3_3_water_limit ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
r.vcov3a <-cluster.vcov(r3a, as.factor(rajguj$a3_4_1_vill_code))
coefr3a <- coeftest(r3a, r.vcov3a)

r3b <- lm(h3_3_water_limit ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media +  as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
r.vcov3b <-cluster.vcov(r3b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr3b <- coeftest(r3b, r.vcov3b)

r3c <- lm(h3_3_water_limit ~b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
r.vcov3c <-cluster.vcov(r3c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr3c <- coeftest(r3c, r.vcov3c)

# limits on electricity use
r4a <- lm(h3_4_elec_limit ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
r.vcov4a <-cluster.vcov(r4a, as.factor(rajguj$a3_4_1_vill_code))
coefr4a <- coeftest(r4a, r.vcov4a)

r4b <- lm(h3_4_elec_limit ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
r.vcov4b <-cluster.vcov(r4b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr4b <- coeftest(r4b, r.vcov4b)

r4c <- lm(h3_4_elec_limit ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media+ as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
r.vcov4c <-cluster.vcov(r4c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr4c <- coeftest(r4c, r.vcov4c)

fit.list.r3_4 <- list(r3a,r3b,r3c,r4a,r4b,r4c)
ser3_4 <- list(coefr3a[,2],coefr3b[,2],coefr3c[,2],coefr4a[,2],coefr4b[,2],coefr4c[,2])

cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes3and4.tex")
stargazer(title = "Government Limits",
          se = ser3_4,
          header = F,
          fit.list.r3_4,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Groundwater Extraction", "Electricity Used"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","Yes","No","Yes")))
sink()

####
## Opposition to Electricity Metering: Note: higher values mean more opposition to the implementation of electricity metering
####

r5a <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
r.vcov5a <-cluster.vcov(r5a, as.factor(rajguj$a3_4_1_vill_code))
coefr5a <- coeftest(r5a, r.vcov5a)

r5b <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media + as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
r.vcov5b <-cluster.vcov(r5b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr5b <- coeftest(r5b, r.vcov5b)

r5c <- lm(h3_2_price_pref ~ b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
r.vcov5c <-cluster.vcov(r5c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr5c <- coeftest(r5c, r.vcov5c)

fit.list.r5 <- list(r5a,r5b,r5c)
ser5 <- list(coefr5a[,2],coefr5b[,2],coefr5c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes5.tex")
stargazer(title = "Predictors of Opposition to Implementation of Electric Metering",
          se = ser5,
          header = F,
          fit.list.r5,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Opposition to Implementation of Electric Metering"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes")))
          sink()

####
## Measures of Support for Diesel Subsidies
####          
          
r6a <- lm(h3_6_subsidy ~  b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
d.vcovr6a <-cluster.vcov(r6a, as.factor(rajguj$a3_4_1_vill_code)) 
coefr6a <- coeftest(r6a, d.vcovr6a)

r6b <- lm(h3_6_subsidy ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl +social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
d.vcovr6b <-cluster.vcov(r6b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr6b <- coeftest(r6b, d.vcovr6b)

r6c <- lm(h3_6_subsidy ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) +as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
d.vcovr6c <-cluster.vcov(r6c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr6c <- coeftest(r6c, d.vcovr6c)

# support for a price ceiling on diesel

r7a <- lm(h3_7_price_ceiling ~  b2_4_trust_stategov + b2_5_trust_natlgov + as.factor(a3_4_village),data=rajguj)
d.vcovr7a <-cluster.vcov(r7a, as.factor(rajguj$a3_4_1_vill_code)) 
coefr7a <- coeftest(r7a, d.vcovr7a)

r7b <- lm(h3_7_price_ceiling ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) + as.factor(a3_4_village),data=rajguj)
d.vcovr7b <-cluster.vcov(r7b, as.factor(rajguj$a3_4_1_vill_code)) 
coefr7b <- coeftest(r7b, d.vcovr7b)

r7c <- lm(h3_7_price_ceiling ~  b2_4_trust_stategov + b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital +media+ as.factor(e1_1_source) +as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=rajguj)
d.vcovr7c <-cluster.vcov(r7c, as.factor(rajguj$a3_4_1_vill_code)) 
coefr7c <- coeftest(r7c, d.vcovr7c)

fit.list.r6_7 <- list(r6a,r6b,r6c,r7a,r7b,r7c)
ser6_7 <- list(coefr6a[,2],coefr6b[,2],coefr6c[,2],coefr7a[,2],coefr7b[,2],coefr7c[,2])
cov.labs <- c("Trust in State Govt.", "Trust in National Govt.", "Elec Pump", "Diesel Pump","Social Capital (index)","News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.labs <- c("Village FE", "Source FE", "Govt caste FE")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/rj.outcomes6and7.tex")
stargazer(title = "Diesel: Subsidy and Price Supports",
          se = ser6_7,
          header = F,
          fit.list.r6_7,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Diesel Subsidy Support", "Dielse Price Ceiling Suppport"),
          add.lines = list(c("Block FE?","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","Yes","No","Yes")))
sink()

#######################################################
#######################################################
### HISTOGRAMS ##
#######################################################
#######################################################

# wd for figures
setwd("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Figures")

# bihar subset (in case entire script above run above)
bihar <- subset(water,water$a3_1_st_code==10)

## Histograms for Bihar trade-off questions

pdf(file = "bar_bihar.pdf", height = 3, width = 6)
par(mfrow = c(1, 2))
barplot(prop.table(table(factor(bihar$h4_4_subsidy_tradeoff1,levels=1:5))), xlab="Subsidy Tradeoff 1",ylab="Share",main="Subsidy Tradeoff Question 1",cex.main=0.75, ylim=c(0,0.6),xlim=c(0,6))
#abline(v=mean(bihar$h4_4_subsidy_tradeoff1,levels=1:5),col="red", lty = 2)
barplot(prop.table(table(factor(bihar$h4_5_subsidy_tradeoff2,levels=1:5))), xlab="Subsidy Tradeoff 2",ylab="Share",main="Subsidy Tradeoff Question 2",cex.main=0.75,ylim=c(0,0.6),xlim=c(0,6))
#abline(v=mean(bihar$h4_5_subsidy_tradeoff2,levels=1:5),col="red", lty = 2)
dev.off()

# - Histograms for Gujarat-Rajasthan trade-off questions

# raj-guj subset (in case not run above)
rajguj <- subset(water,water$a3_1_st_code!=10)

pdf(file = "bar_rajguj.pdf", height = 4, width = 6)
barplot(prop.table(table(factor(rajguj$h3_2_price_pref,levels=1:5))), xlab="No price increase <<-->> Higher prices for reliability",ylab="Share",main="Electricity Reliability vs. Pricing",cex.main=0.75,ylim=c(0,0.8),xlim=c(0,6))
#abline(v=mean(rajguj$h3_2_price_pref,levels=1:5),col="red", lty = 2)
dev.off()



#########################
#########################
## Reliability Descriptives: Guj VS. RAJ
#########################
#########################

guj <- subset(water,water$a3_1_st_code==24)
raj <- subset(water,water$a3_1_st_code==8)

# avail kharif
mean(na.omit(guj$d2_9e_elec_kharif_avail)) # 7.8
mean(na.omit(raj$d2_9e_elec_kharif_avail)) # 5.88

# avail rabi
mean(na.omit(guj$d2_9f_elec_rabi_avail)) # 7.79
mean(na.omit(raj$d2_9f_elec_rabi_avail)) # 6.04

# less than a day outages

mean(na.omit(guj$d2_9g_elec_out_short)) # 1.81
mean(na.omit(raj$d2_9g_elec_out_short)) # 4.11
# WAY MORE OUTAGES In RAJASTHAN

# longer than one day outages
mean(na.omit(guj$d2_9h_elec_out_long)) # 1.29
mean(na.omit(raj$d2_9h_elec_out_long)) # 1.87

# do they know when the power will go out ahead of time?
# 1 yes usually, 2 yes, sometimes, and 3 NO
mean(na.omit(guj$d2_9i_elec_out_ahead)) # 1.32
mean(na.omit(raj$d2_9i_elec_out_ahead)) # 1.51
# GUJ more often likely to know ahead of time.

## voltage fluctuations
mean(na.omit(guj$d2_9j_volt)) # 1.54
mean(na.omit(raj$d2_9j_volt)) # 3.38
# way more likely in raj # note that the timeperiods vary only slightly across 
# obvs - most are months, some are weeks
guj$d2_9j_timeperiod
raj$d2_9j_timeperiod

## motor burnout
mean(na.omit(guj$d2_9k_burnout)) # 1.64
mean(na.omit(raj$d2_9k_burnout)) # 1.81

guj$d2_9k_timeperiod
raj$d2_9k_timeperiod
# totally diff time periods. can't use this one w/o cleaning..

# comparing open-ended
raj$e2_1_open_ended
guj$e2_1_open_ended
# electricity issue is def mentioned more in rajasthan.

# does this mean different amounts are irrigated? - rabi
mean(na.omit(guj$c1_22a_rabi_irrigated)) # 4.88
mean(na.omit(raj$c1_22a_rabi_irrigated)) # 4.85

# does this mean different amounts are irrigated? - kharif
mean(na.omit(guj$c1_23a_kharif_irrigated)) # 5.44
mean(na.omit(raj$c1_23a_kharif_irrigated)) # 3.8

#  yes indeed - huge diffs. 

# groundwater - rabi?
mean(na.omit(guj$c1_22b_rabi_ground_irrigated)) # 4.71
mean(na.omit(raj$c1_22b_rabi_ground_irrigated)) # 4.70

# groundwater - kharif?
mean(na.omit(guj$c1_23b_kharif_ground_irrigated)) # 4.95
mean(na.omit(raj$c1_23b_kharif_ground_irrigated)) # 3.42

# all bighas
guj$c1_22a_unit
raj$c1_22a_unit

guj$c1_22b_unit
raj$c1_22b_unit

guj$c1_23a_unit
raj$c1_23a_unit

# rabi and karif earnings

# main / rabi
mean(na.omit(guj$d1_1d_main_earnings)) # 15143
mean(na.omit(raj$d1_1d_main_earnings)) # 14724

# secondary / kharif
mean(na.omit(guj$d1_2d_kharif_earnings)) # 15614
mean(na.omit(raj$d1_2d_kharif_earnings)) # 11189
colnames(rajguj)

##################################
##################################
#### Holding State Trust Constant --
#### Does Central Still Predict Policy Preferences?
##################################
##################################

##### 
# Descriptives of Variance of NAtl Trust, added 23 August 2016
##### 

# First for Low State Trust

mean(l$b2_5_trust_natlgov) # 2.20
sd(l$b2_5_trust_natlgov) # 1.35

mean(na.omit(m$b2_5_trust_natlgov)) # 3.24
sd(na.omit(m$b2_5_trust_natlgov)) # .68

mean(h$b2_5_trust_natlgov) # 4.48
sd(h$b2_5_trust_natlgov) # .75

# Descriptive Histograms

setwd("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Figures")
pdf(file = "trust_var_exp.pdf", height = 8, width = 5)
par(mfrow = c(3, 1)) 
barplot(prop.table(table(factor(l$b2_5_trust_natlgov,levels=1:5))), xlab="Trust in National Government",ylab="Share",main="Population With Low Trust in State Government",cex.main=1.3, ylim=c(0,0.6),xlim=c(0,6))
barplot(prop.table(table(factor(m$b2_5_trust_natlgov,levels=1:5))), xlab="Trust in National Government",ylab="Share",main="Population With Neutral Trust in State Government",cex.main=1.3, ylim=c(0,0.8),xlim=c(0,6))
barplot(prop.table(table(factor(h$b2_5_trust_natlgov,levels=1:5))), xlab="Trust in National Government",ylab="Share",main="Population With High Trust in State Government",cex.main=1.3, ylim=c(0,0.6),xlim=c(0,6))
dev.off()

# - Histograms for Gujarat-Rajasthan trade-off questions

# raj-guj subset (in case not run above)
rajguj <- subset(water,water$a3_1_st_code!=10)

pdf(file = "bar_rajguj.pdf", height = 4, width = 6)
barplot(prop.table(table(factor(rajguj$h3_2_price_pref,levels=1:5))), xlab="No price increase <<-->> Higher prices for reliability",ylab="Share",main="Electricity Reliability vs. Pricing",cex.main=0.75,ylim=c(0,0.8),xlim=c(0,6))
#abline(v=mean(rajguj$h3_2_price_pref,levels=1:5),col="red", lty = 2)
dev.off()



### elec in last election

# elec in last election - LOW 
model1al <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in last election - MIDDLE

model1am <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in last election - HIGH

model1ah <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec1.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Electricity Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                           c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                           c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                           c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

#######################

### elec in previous election

# elec in prev election - LOW 
model1al <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in prev election - MIDDLE

model1am <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in prev election - HIGH

model1ah <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec2.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Electricity Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in last election

# dsl in last election - LOW 
model1al <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in last election - MIDDLE

model1am <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in last election - HIGH

model1ah <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for diesel in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl1.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
suppress.errors = F,float = F,
dep.var.labels = c("Diesel Policy Importance in Last Election"),
#column.labels = c("Low","Middle","High"),
#column.separate = c(3,3,3),
add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()
                              
###### diesel in previous election

# elec in last election - LOW 
model1al <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in prev election - MIDDLE

model1am <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)
                              
model1cm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)
                              
# dsl in prev election - HIGH
                              
model1ah <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)
                              
model1bh <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for dsl in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])
                              
cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")
                              
sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl2.tex")
stargazer(fit.list,
se = se.list,
header = F,
covariate.labels = cov.labs,
omit.stat = omit.stats,
omit = omit.list,
no.space = T,
suppress.errors = F,float = F,
dep.var.labels = c("Diesel Policy Importance in Previous Election"),
#column.labels = c("Low","Middle","High"),
#column.separate = c(3,3,3),
add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

#################################
#################################
### Now l,m,h Estimated for Tradeoffs
#################################
#################################

#################################
### Reliability vs. Pricing, Raj/Gujarat Only r_pref
#################################

# - Reliability vs. Pricing, Raj/Gujarat Only  LOW 
model1al <- lm(r_pref ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# - Reliability vs. Pricing, Raj/Gujarat Only MIDDLE

model1am <- lm(r_pref ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# - Reliability vs. Pricing, Raj/Gujarat Only HIGH

model1ah <- lm(r_pref ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(r_pref ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for reliability vs. pricing Raj/Guj

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_tradeoff1.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c(""),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()


###################################
## Bihar Subsidy Tradeoff 1
###################################

### Bihar Subsidy Trade Off 1

# - Bihar Subsidy Trade Off 1  LOW 

model1al <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# - Bihar Subsidy Trade Off 1 MIDDLE

model1am <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h4_4_subsidy_tradeoff1~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# - Bihar Subsidy Trade Off 1  HIGH

model1ah <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h4_4_subsidy_tradeoff1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h4_4_subsidy_tradeoff1~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for Bihar Subsidy Trade off 1

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_tradeoff2.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c(""),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

######################################
### Bihar Subsidy Tradeoff 2
######################################

### Bihar Subsidy Trade Off 2

# - Bihar Subsidy Trade Off 2  LOW 

model1al <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=l)
m.vcov1al <-cluster.vcov(model1al, as.factor(l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# - Bihar Subsidy Trade Off 2 MIDDLE

model1am <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=m)
m.vcov1am <-cluster.vcov(model1am, as.factor(m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h4_5_subsidy_tradeoff2~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# - Bihar Subsidy Trade Off 2  HIGH

model1ah <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h4_5_subsidy_tradeoff2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h4_5_subsidy_tradeoff2~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for Bihar Subsidy Trade off 2

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_tradeoff3.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c(""),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()


##########################################################
##########################################################
##########################################################
##########################################################
##########################################################
##########################################################
### Now separate for each state
##########################################################
##########################################################
##########################################################
##########################################################
##########################################################
##########################################################

##########################################################
##########################################################
### RAJ
##########################################################
##########################################################

### elec in last election

# elec in last election - LOW 
model1al <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(r.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(r.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(r.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in last election - MIDDLE

model1am <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(r.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(r.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(r.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in last election - HIGH

model1ah <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(r.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(r.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(r.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec1RAJONLYRAJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Electricity Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

#######################

### elec in previous election

# elec in prev election - LOW 
model1al <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(r.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(r.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(r.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in prev election - MIDDLE

model1am <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(r.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(r.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(r.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in prev election - HIGH

model1ah <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(r.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(r.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(r.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec2RAJONLYRAJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Electricity Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in last election

# dsl in last election - LOW 
model1al <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(r.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(r.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(r.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in last election - MIDDLE

model1am <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(r.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(r.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(r.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in last election - HIGH

model1ah <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(r.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(r.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(r.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for diesel in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl1RAJONLYRAJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Diesel Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in previous election

# elec in last election - LOW 
model1al <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(r.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(r.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(r.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in prev election - MIDDLE

model1am <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(r.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(r.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(r.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in prev election - HIGH

model1ah <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=r.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(r.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=r.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(r.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=r.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(r.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for dsl in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl2RAJONLYRAJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.var.labels = c("Diesel Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

##########################################################
##########################################################
### GUJ
##########################################################
##########################################################

### elec in last election

# elec in last election - LOW 
model1al <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(g.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(g.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(g.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in last election - MIDDLE

model1am <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(g.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(g.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(g.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in last election - HIGH

model1ah <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(g.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(g.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(g.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec1GUJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vag.labels = c("Electricity Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

#######################

### elec in previous election

# elec in prev election - LOW 
model1al <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(g.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(g.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(g.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in prev election - MIDDLE

model1am <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(g.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(g.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(g.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in prev election - HIGH

model1ah <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(g.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(g.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(g.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec2GUJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vag.labels = c("Electricity Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in last election

# dsl in last election - LOW 
model1al <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(g.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(g.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(g.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in last election - MIDDLE

model1am <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(g.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(g.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(g.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in last election - HIGH

model1ah <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(g.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(g.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(g.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for diesel in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl1GUJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vag.labels = c("Diesel Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in previous election

# elec in last election - LOW 
model1al <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(g.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(g.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(g.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in prev election - MIDDLE

model1am <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(g.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(g.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(g.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in prev election - HIGH

model1ah <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=g.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(g.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=g.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(g.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=g.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(g.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for dsl in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl2GUJONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vag.labels = c("Diesel Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

##########################################################
##########################################################
### BIHAR
##########################################################
##########################################################

### elec in last election

# elec in last election - LOW 
model1al <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(b.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(b.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(b.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in last election - MIDDLE

model1am <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(b.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(b.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(b.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in last election - HIGH

model1ah <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(b.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(b.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_1_elec_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(b.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec1BIHARONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vab.labels = c("Electricity Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

#######################

### elec in previous election

# elec in prev election - LOW 
model1al <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(b.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(b.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(b.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# elec in prev election - MIDDLE

model1am <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(b.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(b.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(b.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# elec in prev election - HIGH

model1ah <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(b.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(b.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_2_elec_policy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(b.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for electricity in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_elec2BIHARONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vab.labels = c("Electricity Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in last election

# dsl in last election - LOW 
model1al <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(b.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(b.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(b.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in last election - MIDDLE

model1am <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(b.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(b.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(b.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in last election - HIGH

model1ah <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(b.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(b.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_3_dsl_policy_impt1 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(b.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for diesel in last election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl1BIHARONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vab.labels = c("Diesel Policy Importance in Last Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()

###### diesel in previous election

# elec in last election - LOW 
model1al <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.l)
m.vcov1al <-cluster.vcov(model1al, as.factor(b.l$a3_4_1_vill_code)) 
coef1al <- coeftest(model1al, m.vcov1al)

model1bl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.l)
m.vcov1bl <-cluster.vcov(model1bl, as.factor(b.l$a3_4_1_vill_code)) 
coef1bl <- coeftest(model1bl, m.vcov1bl)

model1cl <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.l)
m.vcov1cl <-cluster.vcov(model1cl, as.factor(b.l$a3_4_1_vill_code)) 
coef1cl <- coeftest(model1cl, m.vcov1cl)

# dsl in prev election - MIDDLE

model1am <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.m)
m.vcov1am <-cluster.vcov(model1am, as.factor(b.m$a3_4_1_vill_code)) 
coef1am <- coeftest(model1am, m.vcov1am)

model1bm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.m)
m.vcov1bm <-cluster.vcov(model1bm, as.factor(b.m$a3_4_1_vill_code)) 
coef1bm <- coeftest(model1bm, m.vcov1bm)

model1cm <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.m)
m.vcov1cm <-cluster.vcov(model1cm, as.factor(b.m$a3_4_1_vill_code)) 
coef1cm <- coeftest(model1cm, m.vcov1cm)

# dsl in prev election - HIGH

model1ah <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + as.factor(a3_4_village),data=b.h)
m.vcov1ah <-cluster.vcov(model1ah, as.factor(b.h$a3_4_1_vill_code)) 
coef1ah <- coeftest(model1ah, m.vcov1ah)

model1bh <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) + as.factor(a3_4_village),data=b.h)
m.vcov1bh <-cluster.vcov(model1bh, as.factor(b.h$a3_4_1_vill_code)) 
coef1bh <- coeftest(model1bh, m.vcov1bh)

model1ch <- lm(h1_4_dsl_polcy_impt2 ~  b2_5_trust_natlgov + d2_8_elec + d2_10_dsl + social_capital + media + as.factor(e1_1_source) +
                 as.factor(a3_4_village) + log_land + log_expenditure + b1_4_school + as.factor(b1_6a_govt_caste), data=b.h)
m.vcov1ch <-cluster.vcov(model1ch, as.factor(b.h$a3_4_1_vill_code)) 
coef1ch <- coeftest(model1ch, m.vcov1ch)

# table for l,m,h split for dsl in prev election

fit.list <- list(model1al,model1bl,model1cl,model1am,model1bm,model1cm,model1ah,model1bh,model1ch)
se.list <- list(coef1al[,2],coef1bl[,2],coef1cl[,2],coef1am[,2],coef1bm[,2],coef1cm[,2],coef1ah[,2],coef1bh[,2],coef1ch[,2])

cov.labs <- c("Trust in National Govt.", "Elec Pump", "Diesel Pump", "Social Capital (index)", "News Exposure", "Land Owned (log)","Monthly Expenditure (log)", "Years of Schooling")
omit.list <-c("a3_4_village", "e1_1_source", "b1_6a_govt_caste")
omit.stats <- c("rsq","ser","f")

sink("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Tables/natl_dsl2BIHARONLY.tex")
stargazer(fit.list,
          se = se.list,
          header = F,
          covariate.labels = cov.labs,
          omit.stat = omit.stats,
          omit = omit.list,
          no.space = T,
          suppress.errors = F,float = F,
          dep.vab.labels = c("Diesel Policy Importance in Previous Election"),
          #column.labels = c("Low","Middle","High"),
          #column.separate = c(3,3,3),
          add.lines = list( c("State Govt. Trust","Low","Low","Low","Middle","Middle","Middle","High","High","High"),
                            c("Village FE?","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"),
                            c("Irrigation Source FE?","No","Yes","Yes","No","Yes","Yes","No","Yes","Yes"),
                            c("Government Caste FE?","No","No","Yes","No","No","Yes","No","No","Yes")))
sink()


################################ #############################
################################ #############################
### Exploration of H38 relative importance effects - Jan 31, 2017
################################ #############################
################################ #############################

# first verifying that the data is entered correctly - all values should sum to 15

rajguj$prior_verif <- rajguj$h3_8a_rank1 +rajguj$h3_8b_rank2 + rajguj$h3_8c_rank3 + rajguj$h3_8d_rank4  + rajguj$h3_8e_rank5
summary(rajguj$prior_verif)

P <- rajguj[!is.na(rajguj$prior_verif),]
summary(P$prior_verif)

## so we drop bihar + 5 NAs

### now for some descriptives

hist(P$h3_8a_rank1)
hist(P$h3_8b_rank2)
hist(P$h3_8c_rank3)
hist(P$h3_8d_rank4)
hist(P$h3_8e_rank5)

# priorirty means - lower is higher prior
mean(P$h3_8a_rank1) # 2.92 for health
mean(P$h3_8b_rank2) # 2.13 for guaranteed low electricity prices
mean(P$h3_8c_rank3) # 3.10 for farming equipment
mean(P$h3_8d_rank4) # 3.78 for diesel
mean(P$h3_8e_rank5) # 3.07 for education

setwd("~/Dropbox/Water_MeirVijayJohannes/Manuscript_POLECON/Figures")
pdf(file = "policy_priorities_rajguj.pdf", height = 8, width = 6)
par(mfrow = c(3, 2)) 
barplot((table(factor(P$h3_8a_rank1,levels=1:5))), xlab="Relative Policy Priority",ylab="Respondents (#)",main="Access to Health Clinics",cex.main=1.3, ylim=c(0,500),xlim=c(0,6))
abline(v=mean(P$h3_8a_rank1), lty=2)
barplot((table(factor(P$h3_8b_rank2,levels=1:5))), xlab="Relative Policy Priority",ylab="Respondents (#)",main="Low Electricity Prices",cex.main=1.3, ylim=c(0,500),xlim=c(0,6))
abline(v=mean(P$h3_8b_rank2), lty=2)
barplot((table(factor(P$h3_8c_rank3,levels=1:5))), xlab="Relative Policy Priority",ylab="Respondents (#)",main="Loans for Farming Equipment",cex.main=1.3, ylim=c(0,500),xlim=c(0,6))
abline(v=mean(P$h3_8c_rank3), lty=2)
barplot((table(factor(P$h3_8d_rank4,levels=1:5))), xlab="Relative Policy Priority",ylab="Respondents (#)",main="Diesel Subsidies",cex.main=1.3, ylim=c(0,500),xlim=c(0,6))
abline(v=mean(P$h3_8d_rank4), lty=2)
barplot((table(factor(P$h3_8e_rank5,levels=1:5))), xlab="Relative Policy Priority",ylab="Respondents (#)",main="Quality Education",cex.main=1.3, ylim=c(0,500),xlim=c(0,6))
abline(v=mean(P$h3_8e_rank5), lty=2)
dev.off()

##### More Prioritization Descriptives

View(table(water$h3_8a_rank1)) # 214 #1s
View(table(water$h3_8b_rank2)) # 556 #1s, 307#2, 268 #3, 125#4, 69#5
View(table(water$h3_8c_rank3)) # 112 #1a
View(table(water$h3_8d_rank4)) # 107 #1s
View(table(water$h3_8e_rank5)) # 286 #1s

556/(214+556+112+107+286) # 44% rank it number 1
863/(214+556+112+107+286) # 68% rank it number 1 or 2

69/ (214+556+112+107+286) # 5% rank it 5th!

### sources of water, surface/ground/canal

View(table(water$e1_1_source))

171/2010 #8.5 pct no irrigation
281/2010 #14 pct only surface water
1250/2010 # 62% only groundwater
303/2010 #15% both surface/groundwater

#########################
#########################
### More Descriptives
#########################
#########################

# depth

summary(water$e2_8_rabi_depth_dummy) #.55 overall
summary(bihar$e2_8_rabi_depth_dummy) # .64
summary(raj$e2_8_rabi_depth_dummy) # .56
summary(guj$e2_8_rabi_depth_dummy) # .44

summary(water$e2_9_kharif_depth_dummy) #.59 overall
summary(bihar$e2_9_kharif_depth_dummy) # .64
summary(raj$e2_9_kharif_depth_dummy) # .71
summary(guj$e2_9_kharif_depth_dummy) # .43

# 

View(table(water$e2_8b_rabi_depth_comparison)) # 5 dks whole survey
View(table(water$e2_9b_kharif_depth_comparison)) # 2 dks whole survey